package com.iims.market.flow;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.iims.common.vo.BusinessInfo;
import com.iims.market.domain.Contract;
import com.iims.market.domain.PurposeContract;
import com.iims.market.service.IContractService;
import com.iims.market.service.IPurposeContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 市场业务数据生成器
 * 需要配置到cmis_flow_business_key_conf
 *
 * @author fanpei
 * @date 2021/7/16 23:16
 */
@Component
public class MarketBusinessGenerator {

    @Autowired
    private IPurposeContractService purposeContractService;

    @Autowired
    private IContractService contractService;

    /**
     * 生成意向合同业务信息生成
     *
     * @param jsonStr
     * @return
     */
    public BusinessInfo genPurPoseContractBusinessInfo(String jsonStr) {
        PurposeContract purposeContract = JSONUtil.toBean(jsonStr, PurposeContract.class);
        PurposeContract purposeContractTmp=purposeContractService.selectDetailById(purposeContract.getPurposeContractId());
        BusinessInfo businessKeyId = new BusinessInfo();
        businessKeyId.setTargetId(purposeContract.getPurposeContractId());
        businessKeyId.setBusinessKey(StrUtil.join("","PURPOSE_CONTRACT-", purposeContractTmp.getPcontractCode()));
        businessKeyId.setBusinessClass("com.iims.market.service.impl.PurposeContractServiceImpl");
        businessKeyId.setBusinessMethod("selectDetailById");
        return businessKeyId;
    }

    /**
     * 生成正式合同业务信息
     * @param jsonStr
     * @return
     */
    public BusinessInfo genContractBusinessInfo(String jsonStr) {
        Contract contract = JSONUtil.toBean(jsonStr, Contract.class);
        Contract contractTmp=contractService.selectDetailById(contract.getContractId());
        BusinessInfo businessKeyId = new BusinessInfo();
        businessKeyId.setTargetId(contract.getContractId());
        businessKeyId.setBusinessKey(StrUtil.join("","CONTRACT-", contractTmp.getContractCode()));
        businessKeyId.setBusinessClass("com.iims.market.service.impl.ContractServiceImpl");
        businessKeyId.setBusinessMethod("selectDetailById");
        return businessKeyId;
    }
}
